home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / ENVIRO.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  4KB  |  117 lines

  1. ;****************************;
  2. ; WASM Environment Access    ;
  3. ; By Eric Tauck              ;
  4. ;                            ;
  5. ; Defines:                   ;
  6. ;                            ;
  7. ;   EnvPro  get program name ;
  8. ;   EnvRes  reset reader     ;
  9. ;   EnvGet  get next string  ;
  10. ;****************************;
  11.  
  12. ;--- initialization
  13.  
  14.         mov     _env_prg,0FFFFH ;default unavailable
  15.         mov     ah, 30H         ;get DOS version function
  16.         int     21H             ;execute
  17.         cmp     al, 3           ;check if at least 3
  18.         jb      _env_2          ;jump if not
  19.  
  20.         push    es
  21.         mov     es, [_ENV_SEG]  ;load segment
  22.         sub     di, di          ;start of environment
  23.         sub     al, al          ;byte to search for
  24.         mov     cx, 0FFFFH      ;bytes to search
  25.         cld
  26. _env_1  repne
  27.         scasb                   ;scan for zero
  28.         seg     es
  29.         cmp     BYTE [di], 0    ;check if end of environment
  30.         jne     _env_1          ;loop back if not
  31.  
  32.         add     di, 3           ;skip to program name
  33.         mov     _env_prg, di    ;save address
  34.         pop     es
  35.  
  36. _env_2  call    EnvRes          ;reset environment pointer
  37.         jmps    _enviro_end
  38.  
  39. ;--- data
  40.  
  41. _ENV_SEG        EQU     2CH     ;address of environment segment
  42. _env_prg        DW      ?       ;offset of program name
  43. _env_ptr        DW      0       ;current read offset
  44.  
  45. ;========================================
  46. ; Return the address of the program name.
  47. ;
  48. ; Out: DX:AX= name address; CY= set if
  49. ;      unavailable (i.e. DOS pre-3.0).
  50.  
  51. EnvPro  PROC    NEAR
  52.         mov     ax, _env_prg    ;load offset
  53.         cmp     ax, 0FFFFH      ;check if illegal
  54.         je      _evprg1         ;jump if so
  55.         mov     dx, [_ENV_SEG]  ;return segment
  56.         clc
  57.         ret
  58. _evprg1 stc
  59.         ret
  60.         ENDP
  61.  
  62. ;========================================
  63. ; Reset environment reader.
  64.  
  65. EnvRes  PROC    NEAR
  66.         push    ds
  67.         mov     ds, [_ENV_SEG]  ;segment
  68.         sub     ax, ax          ;default address
  69.         cmp     BYTE [0], 0     ;check if end of environment strings
  70.         jne     _evres1
  71.         mov     ax, 0FFFFH      ;end flag
  72. _evres1 pop     ds
  73.         mov     _env_ptr, ax    ;save address/flag
  74.         ret
  75.         ENDP
  76.  
  77. ;========================================
  78. ; Return address of next string.
  79. ;
  80. ; Out: DX:AX= next environment string
  81. ;      address; CY= set if no more.
  82.  
  83. EnvGet  PROC    NEAR
  84.         mov     ax, _env_ptr    ;load pointer
  85.         cmp     ax, 0FFFFH      ;check if end of environment strings
  86.         je      _evget2         ;jump if so
  87.         push    ax              ;save for return
  88.         push    di
  89.         push    es
  90.         mov     di, ax          ;search start address
  91.         mov     es, [_ENV_SEG]  ;load segment
  92.         sub     al, al          ;look for end of this string
  93.         mov     cx, 0FFFFH      ;bytes to search
  94.         cld                     ;clear direction
  95.         repne
  96.         scasb                   ;scan for zero
  97.         mov     dx, es          ;return segment in DX
  98.         mov     ax, di          ;pointer to next string
  99.         seg     es
  100.         cmp     BYTE [di], 0    ;check if end of strings
  101.         jne     _evget1
  102.         mov     ax, 0FFFFH      ;end of string flag
  103. _evget1 mov     _env_ptr, ax    ;save next address
  104.         pop     es
  105.         pop     di
  106.         pop     ax
  107.         clc
  108.         ret
  109.  
  110. ;--- no environment string returned
  111.  
  112. _evget2 stc
  113.         ret
  114.         ENDP
  115.  
  116. _enviro_end
  117.